package cn.liyicun.cp.cpweb.controller.admin;

import cn.liyicun.cp.cpweb.base.Result;
import cn.liyicun.cp.cpweb.entity.MoneyLog;
import cn.liyicun.cp.cpweb.entity.MoneyRecharge;
import cn.liyicun.cp.cpweb.entity.MoneyWithdraw;
import cn.liyicun.cp.cpweb.service.MoneyLogService;
import cn.liyicun.cp.cpweb.service.MoneyService;
import cn.liyicun.cp.cpweb.service.money.RechargeService;
import cn.liyicun.cp.cpweb.service.money.WithdrawService;
import cn.liyicun.cp.cpweb.util.CPConstant;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping(value = {CPConstant.ROOT_PHONE_ADMIN + "/money"})
public class MoneyAdminController extends BaseAdminController {

    @Autowired
    MoneyService moneyService;
    @Autowired
    MoneyLogService moneyLogService;

    @Autowired
    RechargeService rechargeService;
    @Autowired
    WithdrawService withdrawService;


    @RequestMapping(value = "/moneyStatus", method = RequestMethod.POST)
    @ResponseBody
    public Result<?> moneyStatus(HttpServletRequest request,
                                 @RequestParam(value = "type", required = true) String type,
                                 @RequestParam(value = "id", required = true) Long id,
                                 @RequestParam(value = "status", required = true) String status,
                                 @RequestParam(value = "remark", required = true) String remark) {
        moneyService.ext(request, type, id, status, remark, null);
        return Result.success("操作成功!");
    }


    @RequestMapping(value = "/searchRecharge")
    public String searchRecharge(HttpServletRequest request, Map<String, Object> map,
                                 @RequestParam(value = "uid", required = false, defaultValue = "0") Long uid,
                                 @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                 @RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
        getLoginByIdError(request);
        PageInfo<MoneyRecharge> pages = rechargeService.search(uid, page, size);
        map.put("pages", pages);
        return "admin/searchRecharge";
    }


    @RequestMapping(value = "/searchWithdraw")
    public String searchWithdraw(HttpServletRequest request, Map<String, Object> map,
                                 @RequestParam(value = "uid", required = false, defaultValue = "0") Long uid,
                                 @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                 @RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
        getLoginByIdError(request);
        PageInfo<MoneyWithdraw> pages = withdrawService.search(uid, page, size);
        map.put("pages", pages);
        return "admin/searchWithdraw";
    }

    @RequestMapping(value = "/searchMoneyLog")
    public String searchMoneyLog(HttpServletRequest request, Map<String, Object> map,
                                 @RequestParam(value = "uid", required = false, defaultValue = "0") Long uid,
                                 @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                 @RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
        getLoginByIdError(request);
        PageInfo<MoneyLog> pages = moneyLogService.search(uid, page, size);
        map.put("pages", pages);
        return "admin/searchMoneyLog";
    }


}
